import axiosInstance from "@/utils/request";

/**
 * 用户基础信息地址
 */
enum Api {
    BASE_URL = '/role',
    PAGE_ROLES = `${BASE_URL}/pageRoles`,
    ADD_ROLE = `${BASE_URL}/addRole`,
    UPDATE_ROLE = `${BASE_URL}/updateRole`,
    DELETE_ROLE_BY_ID = `${BASE_URL}/deleteRoleById`,
    DELETE_ROLE_BY_IDS = `${BASE_URL}/deleteRoleByIds`,
}

export interface Page<T> {
    pageNumber: number
    pageSize: number
    records: T[]
    totalPage: number
    totalRow: number
}

export interface Records {
    id: string
    roleName: string
    roleCode: string
    roleDesc: string
    createTime: string
    updateTime: string
    createUser: string
    updateUser: string
}

/**
 * 分页查询用户信息
 */
export const pageRoles = (data: any) => {
    return axiosInstance({
        url: Api.PAGE_ROLES,
        method: 'post',
        data: data
    })
}

/**
 * 添加角色
 * @param data
 */
export const addRoleReq = (data: any) => {
    return axiosInstance({
        url: Api.ADD_ROLE,
        method: 'post',
        data: data
    })
}

/**
 * 更新角色
 * @param data
 */
export const updateRoleReq = (data: any) => {
    return axiosInstance({
        url: Api.UPDATE_ROLE,
        method: 'post',
        data: data
    })
}

/**
 * 删除角色
 */
export const deleteRoleByIdReq = (id: string) => {
    return axiosInstance({
        url: `${Api.DELETE_ROLE_BY_ID}/${id}`,
        method: 'get'
    })
}

/**
 * 批量删除角色
 * @param ids 角色id数组
 */
export const deleteRoleByIdsReq = (ids: string[]) => {
    return axiosInstance({
        url: Api.DELETE_ROLE_BY_IDS,
        method: 'post',
        data: ids
    })
}
